package com.kupurui.asteacher.adapter;

import android.content.Context;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.android.frame.view.linearlistview.LinearListView;
import com.iarcuschin.simpleratingbar.SimpleRatingBar;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.bean.PreReleaseInfo;
import com.kupurui.asteacher.utils.URLImageParser;

import java.util.List;

/**
 * Created by Administrator on 2017/10/18.
 */

public class PreReleaseTopicAdapter extends CommonAdapter<PreReleaseInfo.QuesBean> {

    PreReleaseChildAdapter adapter;

    public PreReleaseTopicAdapter(Context context, List<PreReleaseInfo.QuesBean> mList, int itemLayoutId) {
        super(context, mList, itemLayoutId);
    }

    @Override
    public void convert(ViewHolder holder, final PreReleaseInfo.QuesBean item, int positon) {
        LinearListView listView = holder.getView(R.id.listview);
        SimpleRatingBar ratingBar = holder.getView(R.id.rating_bar);
        ratingBar.setRating(Float.parseFloat(item.getQuestion().getStar()));
        TextView tvSubject = holder.getView(R.id.tv_subject);
        tvSubject.setText(Html.fromHtml(item.getQuestion().getTitle(), new URLImageParser(mContext,tvSubject), null));
        TextView tvSubjectNum = holder.getView(R.id.tv_subject_num);
        if (item.getQuestion().getType().equals("1")){
            tvSubjectNum.setText((positon+1)+".单选题");
            adapter =new PreReleaseChildAdapter(mContext,item.getOption(),R.layout.radio_item);
            listView.setAdapter(adapter);
        }else if(item.getQuestion().getType().equals("2")){
            tvSubjectNum.setText((positon+1)+".判断题");
            adapter =new PreReleaseChildAdapter(mContext,item.getOption(),R.layout.radio_item);
            listView.setAdapter(adapter);
        }else if (item.getQuestion().getType().equals("3")){
            tvSubjectNum.setText((positon+1)+".填空题");
        }else if(item.getQuestion().getType().equals("4")){
            tvSubjectNum.setText((positon+1)+".解答题");
        }

        final ImageView ivSelector = holder.getView(R.id.iv_selector);
        if (item.getIs_selector()){
            ivSelector.setSelected(true);
        }else{
            ivSelector.setSelected(false);
        }
        ivSelector.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.getIs_selector()){
                    item.setIs_selector(false);
                    ivSelector.setSelected(false);
                }else{
                    item.setIs_selector(true);
                    ivSelector.setSelected(true);
                }
            }
        });
    }
}
